package com.example.selfservicestation.base

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
import com.shencoder.loadingdialog.LoadingDialog

abstract class BaseBindingActivity<VB : ViewBinding> : AppCompatActivity() {
    private lateinit var mMiniLoadingDialog: LoadingDialog
    lateinit var binding: VB

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initMiniLoadingDialog()
        binding = getViewBinding()
        setContentView(binding.root)
    }


    private fun initMiniLoadingDialog() {
        if (!this::mMiniLoadingDialog.isInitialized){
            mMiniLoadingDialog = LoadingDialog.builder(this).setCancelable(true).showHintText(false).create()
        }
    }

    fun dismissLoading() {
        if (mMiniLoadingDialog.isShowing){
            mMiniLoadingDialog.dismiss()
        }
    }

    fun showLoading(showText: String = "请稍候"){
        if (!mMiniLoadingDialog.isShowing){
            mMiniLoadingDialog.setHintText(showText)
            mMiniLoadingDialog.show()
        }
    }


    override fun onDestroy() {
        super.onDestroy()
    }

    abstract fun getViewBinding(): VB

}